package com.atomscat.lottery.config.security;


import com.atomscat.lottery.service.UserEntityService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.userdetails.ReactiveUserDetailsService;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

@Component
@RequiredArgsConstructor
public class SecurityDetailsService implements ReactiveUserDetailsService {

    private final UserEntityService userEntityService;

    @Override
    public Mono<UserDetails> findByUsername(String username) {
        return Mono.just(this.userEntityService.findByUsername(username)
                .orElseThrow(() -> new UsernameNotFoundException("Username: " + username + " not found"))
        );
    }
}